//回文数索引: https://www.nowcoder.com/practice/b6edb5ca15d34b1eb42e4725a3c68eba?
#include <iostream>
#include <string>
using namespace std;
bool IsPalindrome(string& s, int* start, int* end) 
{
    int i = 0;
    int j = s.size() - 1;
    bool result = true;
    while (i <= j) 
    {
        if (s[i] != s[j]) 
        {
            result = false;
            break;
        }
        i++, j--;
    }
    if (start != nullptr) *start = i;
    if (end != nullptr) *end = j;
    return result;
}
int main() 
{
    int num = 0;
    cin >> num;
    while (num) 
    {
        string s;
        cin >> s;
        int start = 0;
        int end = s.size() - 1;
        if (IsPalindrome(s, &start, &end)) 
        {
            cout << -1 << endl; //已经是回文了
        } 
        else 
        {
            s.erase(end, 1);
            if (IsPalindrome(s, nullptr, nullptr)) 
            {
                cout << end << endl;
            } 
            else 
            {
                cout << start << endl;
            }
        }
        num--;
    }
}